package com.study.mqTest.queue;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.util.concurrent.TimeUnit;

public class Consume {

    private static final String URL;

    private static final String USERNAME;

    private static final String PASSWORD;

    static {
        URL = "tcp://127.0.0.1:61616";
        USERNAME = "admin";
        PASSWORD = "admin";
    }

    public static void main(String[] args) {

        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(URL);

        try {

            Connection connection = activeMQConnectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageConsumer myQueue = session.createConsumer(session.createQueue("myQueue01"));

            while (true){
                TextMessage message = (TextMessage) myQueue.receive();
                if (message==null){
                    break;
                }
                System.out.println("一号消费者消费========：" + message.getText());
            }
            myQueue.close();
            session.close();
            connection.close();

        } catch (JMSException e) {
            e.printStackTrace();
        }


    }
}
